<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //转成数字Number()函数   parseInt()转换成整数
        console.log(Number('123'));//123
        console.log(Number('123.4'));//123.4
        console.log(Number('123年'));//NaN
        console.log(Number('2e3'));//2000
        console.log(Number(''));//0
        console.log(Number('true'));//NaN
        console.log(Number('false'));//NaN
        console.log(Number(true));//1
        console.log(Number(false));//0
        console.log(Number(undefined));//NaN
        console.log(Number(null));//0
        console.log(Number('1+1'));//2X  NaN√
        
        //parseInt()函数  将【字符串】转成整数  
        //自动截掉第一个非数字字符后的所有字符
        //如果字符串不是数字开头，则为NaN
        //parseInt()函数不四舍五入
        console.log(parseInt('3.14'));//3
        console.log(parseInt('3.14是圆周率'));//3
        console.log(parseInt('圆周率是3.14'));//NaN
        console.log(parseInt('3.99'));//3
        console.log(parseInt(true));//NaN      true会先被自动转成字符串，即变为‘true’
        console.log(parseInt('3.6'+'5.1'));//3

        //parseFloat()函数   将【字符串】转换成浮点数
        console.log(parseFloat('3.14'));//3.14
        console.log(parseFloat('3.14是圆周率'));//3.14
        console.log(parseFloat('圆周率是3.14'));//NaN
        console.log(parseFloat('3.99'));//3.99
        console.log(parseFloat('12.67.89'));//12.67
        console.log(parseFloat(true));//NaN   true会先被自动转成字符串，即变为‘true’
        console.log(parseFloat('1'));//1


        //转成字符串String()函数  会变得长得相同的字符串 科学计数法和非十进制数会转为十进制值
        console.log(String(123));//'123'
        console.log(String(123.4));//'123.4'
        console.log(String(NaN));//'NaN'
        console.log(String(Infinity));//'Infinity'
        console.log(String(2e3));//'2000'
        console.log(String(0xf));//'15'
        console.log(String(true));//'true'
        console.log(String(undefined));//'undefined'
        console.log(String(null));//'null'

        //转成字符串 .toString()方法
        console.log((123).toString());//123
        a=6
        console.log(a.toString());//6
        console.log(true.toString());//true
        console.log(NaN.toString());//NaN

        //转为布尔值  Boolean（）函数    0，NaN,空,null,undefined都是false,其他为true
        console.log(Boolean(123));//true
        console.log(Boolean(Infinity));//true
        console.log(Boolean(-Infinity));//true
        console.log(Boolean('qbc'));//true
        console.log(Boolean('false'));//true
        console.log(Boolean(0));//flase
        console.log(Boolean(NaN));//flase
        console.log(Boolean(''));//flase
        console.log(Boolean(undefined));//flase
        console.log(Boolean(null));//flase
        
        

        
    </script>
</body>
</html>